package 笔试.科大讯飞;

import org.omg.PortableInterceptor.INACTIVE;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author:谢君臣
 * @Date:2021/10/10-18:45
 * @version:1.0
 * @function:
 */
public class Main01 {
    static int res = Integer.MAX_VALUE;
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] num = scanner.nextLine().split(" ");
        char[][] dp = new char[Integer.parseInt(num[0])][Integer.parseInt(num[0])];
        for (int i = 0; i < dp.length; i++) {
            String line = scanner.nextLine();
            for (int j = 0; j < line.length(); j++) {
                dp[i][j]= line.charAt(j);
            }
        }
        DFS(dp,0,0,0);
        System.out.println(res);
    }
    private static void DFS(char[][] dp,int i,int j,int count) {
        if (i==dp.length-1&&j==dp[0].length-1)res = Math.min(res,count);
        else if (count<res){
            if (dp[i][j]=='#')count++;
            char temp = dp[i][j];
            dp[i][j]='0';
            //上
            if(i-1>=0&&dp[i-1][j]!='0')DFS(dp,i-1,j,count);
            //下
            if(i+1<dp.length&&dp[i+1][j]!='0')DFS(dp,i+1,j,count);
            //左
            if(j-1>=0&&dp[i][j-1]!='0')DFS(dp,i,j-1,count);
            //右
            if(j+1<dp[0].length&&dp[i][j+1]!='0')DFS(dp,i,j+1,count);

            dp[i][j]=temp;
        }
    }
}
